package com.tools.genxsd.entity.type;

import com.tools.genxsd.entity.XsdBaseType;
import com.tools.genxsd.entity.XsdDocument;
import com.tools.genxsd.entity.XsdElement;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

import static com.tools.genxsd.constant.SysConstant.PREFIX;

/**
 * 复杂节点
 * @author: zhoubin
 * @date: 2022/11/9
 */
@Getter
@Setter
public class XsdComplexType extends XsdBaseType {

    /**
     * 类型名
     */
    private String name;

    /**
     * order指示器，限定其下面的节点是选择(choice)还是顺序(sequence)
     */
    private String order;

    /**
     * 其下面子节点的列表
     */
    private List<XsdElement> childList;

    public XsdComplexType(String name, String order) {
        this.setName(name);
        this.order = order;
        this.childList = new ArrayList<>();
    }

    @Override
    public void setChild(XsdElement element) {
        childList.add(element);
    }

    @Override
    public void addToDocument(XsdDocument document) {
        document.addComplexTypeToXsd(this);
    }

    public String getOrder() {
        if (order.contains(PREFIX)) {
            return order;
        }
        return PREFIX + order;
    }
}
